package mvp.com.bbc.rcjavaretrofitdaggermvp.baseAF;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
import com.scwang.smartrefresh.layout.listener.OnMultiPurposeListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;

import java.util.List;

import butterknife.BindView;
import mvp.com.bbc.rcjavaretrofitdaggermvp.R;
import tech.michaelx.loadinglibrary.LoadingLayout;

/**
 * Created by ${cbf} on 2017/12/2.
 */

public class BaseRefreshFragment extends BaseFragment {
    @BindView(R.id.rv_base_recyclerview)
    RecyclerView rvBaseRecyclerview;
    @BindView(R.id.smartrefresh)
    SmartRefreshLayout smartrefresh;
    @BindView(R.id.loadinglayout)
    LoadingLayout loadinglayout;

    @Override
    protected int setContentLayout() {
        return R.layout.base_refresh_loading;
    }

    @Override
    protected void findViews() {

    }

    @Override
    protected void init() {
        rvBaseRecyclerview.setLayoutManager(new LinearLayoutManager(getContext()));
        BaseAdapter adapter = new BaseAdapter(getContext()) {
            @Override
            protected int layoutadapter() {
                return layoutadapter();
            }

            @Override
            protected void layoutData(List<Object> objects, int position) {
                layoutData(objects, position);
            }

            @Override
            protected void layoutFindViewById(View itemView) {
                loadinglayout.loadComplete();

            }
        };
        rvBaseRecyclerview.setAdapter(adapter);

    }

    @Override
    protected void setListeners() {
        loadinglayout.showLoading();
        loadinglayout.setOnRetryLoadListener(new LoadingLayout.OnRetryLoadListener() {
            @Override
            public void onReLoad() {

            }
        });
        smartrefresh.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                refreshlayout.finishRefresh(500);
            }
        });
        smartrefresh.setOnLoadmoreListener(new OnLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                refreshlayout.finishLoadmore(500);
            }
        });
        smartrefresh.setEnableLoadmore(true);

    }

    @Override
    public void onClick(View view) {

    }
}
